﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Order4 : System.Web.UI.Page
{

    // private string uploadDir; //uploadDir变量存放文件保存路径   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)//用户未登录，返回登录界面
        {
            Response.Redirect("Login.aspx");
        }
        else
        {

            MyDataDataContext db = new MyDataDataContext();
            //获取要显示的记录对象
            var order = from r in db.Order
                        join u in db.User on r.BuyerID equals u.UserID
                        join g in db.SaleOfGoods
                        on r.GoodsID equals g.GoodsID
                        where (r.StateOfOrder == 0 && r.SellerID == Session["UserId"].ToString())|| (r.StateOfOrder == 1 & r.SellerID == Session["UserId"].ToString())//0表示订单已完成                                                                                               
                        select new
                        {
                            u.UserNickname,
                            r.OrderID,
                            r.GoodsName,
                            g.Type,
                            r.Price,
                            g.GoodsPicture,
                            r.Time,
                            r.StateOfOrder
                        };//映射需要显示的字段

            gvSaleOfGoods.DataSource = order;
            gvSaleOfGoods.DataBind();
            if (gvSaleOfGoods.Rows.Count != 0)
            {

                lblCart.Text = "";
            }
            else
            {

                lblCart.Text = "无已卖出的订单！";
            }
        }
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.Cells[1].Text == "1")
        {
            e.Row.Cells[1].Text = "进行中";
        }
        else if((e.Row.Cells[1].Text == "0"))
        {
            e.Row.Cells[1].Text = "已完成";
            //e.Row.Cells[2].Visible = false;
        }
    }


    protected void drop1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //下拉列表选择买入还是卖出，显示相应订单
        if (Item.Items[1].Selected)
            Response.Redirect("Order1.aspx");

        if (Item.Items[0].Selected)
            Response.Redirect("Order4.aspx");
    }
}